package com.gxuwz.leaveSystem.service;

import com.gxuwz.leaveSystem.dao.UserDao;
import com.gxuwz.leaveSystem.entity.User;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserService {
    /**
     * 访问用户service层
     * 定义UserDao属性及其setter方法
     */
    private UserDao userDao;
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    /**
     * 检查用户id和密码
     * @param id
     * @param password
     * @return
     */

    public int checkUser(String id,String password,String userType){
        User user =userDao.findUserByid(id);
        if (user.getPassword().equals(password)&&user.getUserType().equals(userType)){
            return 1;
        }
        return 0;
    }

    /**
     * 添加用户
     * @param user
     * @return
     */

    public int addUser(User user){
        return userDao.addUser(user);
    }

    /**
     * 更新用户
     * @param user
     * @return
     */
    public int updateUser(User user){
        return userDao.updateUser(user);
    }

    /**
     * 删除用户
     * @param id
     * @return
     */
    public int deleteUser(String id){
        int num = userDao.deleteUser(id);
        return num;
    }

    public User findUserByid(String id){
        return userDao.findUserByid(id);
    }

    /**
     * 查询全部用户
     * @return
     */

    public List<User> findAllUser(){
        return userDao.findAllUser();
    }

    /**
     * 根据关键字搜索
     * @param keyword
     * @return
     */
    public List<User> searchUsers(String keyword) {
        return userDao.searchUsers(keyword);
    }

}
